package com.xxx.shetuan3.controller;

import com.xxx.shetuan3.common.CommonResult;
import com.xxx.shetuan3.pojo.Activity;

import com.xxx.shetuan3.pojo.Notice;
import com.xxx.shetuan3.pojo.Organization;
import com.xxx.shetuan3.pojo.User;
import com.xxx.shetuan3.service.ChiefService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/chief")
public class ChiefController {
    @Autowired
    private ChiefService chiefService;

    @ApiOperation(value = "查看所管理的社团")
    @GetMapping("/organizations")
    public CommonResult<List<Organization>> pageOrganization(@RequestParam(value = "chiefId") Integer chiefId,
                                                              @RequestParam(value = "start", defaultValue = "1") Integer start,
                                                              @RequestParam(value = "size", defaultValue = "10") Integer size){
        List<Organization> organizationList = chiefService.findOrganizationByChiefId(chiefId,start,size);
        return CommonResult.success(organizationList);
    }

    @ApiOperation(value = "查看某个社团的信息")
    @GetMapping("/organizations/{organizationId}")
    public CommonResult<Organization> queryOrganizationByOrganizationId(@PathVariable(value = "organizationId") Integer organizationId){
        Organization organization = chiefService.findOrganizationByOrganizationId(organizationId);
        return CommonResult.success(organization);
    }

    @ApiOperation(value = "社团报名审批")
    @PostMapping("/approval")
    public CommonResult approval(Integer student_id,Integer organization_id,String state){
        boolean res = chiefService.approveStudentAndOrganization(student_id, organization_id, state);
        return CommonResult.success();
    }

    @ApiOperation(value = "查看已发公告")
    @PostMapping("/notices")
    public CommonResult<List<Notice>> findNotice(@RequestParam("organizationId") Integer organizationId,
                                                 @RequestParam(value = "start", defaultValue = "1") Integer start,
                                                 @RequestParam(value = "size", defaultValue = "10") Integer size){
        List<Notice> noticeList = chiefService.pageNoticeByOrganizationId(organizationId, start, size);
        return CommonResult.success(noticeList);
    }

    @ApiOperation(value = "删除公告")
    @DeleteMapping("/deleteNotice/{notice_id}")
    public CommonResult deleteNoticeById(@PathVariable("notice_id") Integer notice_id){
        boolean res = chiefService.deleteNotice(notice_id);
        return CommonResult.success();
    }

    @ApiOperation(value = "修改公告")
    @PostMapping("/editNotice")
    public CommonResult editNotice(Notice notice){
        boolean res = chiefService.updateNotice(notice);
        return CommonResult.success();
    }

    @ApiOperation(value = "新增公告")
    @PostMapping("/notice")
    public CommonResult addNotice(Notice notice){
        boolean res = chiefService.saveNotice(notice);
        return CommonResult.success();
    }

    @ApiOperation("查看社团所有成员")
    @GetMapping("/organization/{organization_id}")
    public CommonResult<List<User>> findAllUsers(@PathVariable(value = "organization_id") Integer organization_id,
                                   @RequestParam(value = "start", defaultValue = "1") Integer start,
                                   @RequestParam(value = "size", defaultValue = "10") Integer size){
        List<User> userList = chiefService.pageUserByOrganizationId(organization_id,start,size);
        return CommonResult.success(userList);
    }

    @ApiOperation("删除成员")
    @DeleteMapping("/organization")
    public CommonResult deleteStudent(Integer organization_id, Integer user_id){
        boolean res = chiefService.deleteStudentAndOrganizationByStudentIdAndStudentId(organization_id, user_id);
        return CommonResult.success();
    }

    /*
    @ApiOperation(value = "登录")
    @PostMapping("/login")
    public CommonResult chiefLogin(String Cheif_id, String cheif_pwd){
        return CommonResult.success();
    }
    @ApiOperation(value = "查看某个社团的信息")
    @PostMapping("/find_organization")
    public CommonResult<Organization> findOrganization(String organization_id){
        Organization organization = new Organization();
        organization.setOrganizationId(1);
        organization.setOrganizationName("or1");
        organization.setStart(System.currentTimeMillis());
        return CommonResult.success(organization);
    }


    @ApiOperation(value = " 查看所有社团报名信息")
    @PostMapping("/find_regist_info")
    public CommonResult<List<Activity>> find_regists(String organization_id){
        return CommonResult.success();
    }


    @ApiOperation(value = "社团报名审批")
    @PostMapping("/approval")
    public CommonResult approval(String Student_id,String organization_id,String state){
        return CommonResult.success();
    }


    @ApiOperation(value = "查看某个活动的信息")
    @PostMapping("/find_activity")
    public CommonResult find_activity(String activity_id){
        return CommonResult.success();
    }


    @ApiOperation(value = "查看所有活动报名信息")
    @PostMapping("/find_all_activity")
    public CommonResult<List<Activity>> findAllActivity(){

        return CommonResult.success();
    }

    @ApiOperation(value = "活动报名审批")
    @PostMapping("/approval_activity")
    public CommonResult approvalActivity(String student_id,String activity_id,String state){

        return CommonResult.success();
    }


    @ApiOperation(value = "查看所管理所有社团的所有活动")
    @PostMapping("/find_all_activity")
    public CommonResult<List<Activity>> findAllActivity(String cheif_id){
        return CommonResult.success();
    }


    @ApiOperation(value = "查看已发公告")
    @PostMapping("/organization_id")
    public CommonResult<List<Notice>> findNotice(String organization_id){
        List<Notice> notices = new ArrayList();
        for(int i=0;i<5;i++){
            Notice notice = new Notice();
            notice.setNoticeId(i);
            notice.setContend("notice test content"+i);
            notice.setDate(System.currentTimeMillis());
            notice.setOrganizationId(1);
            notices.add(notice);
        }
        return CommonResult.success(notices);
    }

    @ApiOperation(value = "删除公告")
    @PostMapping("/deleteNotice/")
    public CommonResult deleteNoticeById(String organization_id,String notice_id){
        return CommonResult.success();
    }

    @ApiOperation(value = "修改公告")
    @PostMapping("/editNotice")
    public CommonResult editNotice(String notice_id, Notice notice){
        return CommonResult.success();
    }

    @ApiOperation(value = "新增公告")
    @PostMapping("/addNotice")
    public CommonResult addNotice(Notice notice){
        return CommonResult.success();
    }


     */
}
